<?php
   /*
	* uther sina class base
	* 2012.8.7 start
	*/
class Sina
{
	/**
	 * ���캯��
	 * 
	 * @access public
	 * @param mixed $akey ΢������ƽ̨Ӧ��APP KEY
	 * @param mixed $skey ΢������ƽ̨Ӧ��APP SECRET
	 * @param mixed $access_token OAuth��֤���ص�token
	 * @param mixed $refresh_token OAuth��֤���ص�token secret
	 * @return void
	 */
	function __construct( $akey, $skey, $access_token, $refresh_token = NULL)
	{
		$this->oauth = new SinaAuthV2( $akey, $skey, $access_token, $refresh_token );
	}
	
	/**
	 * ����û�UID���ǳƻ�ȡ�û�����
	 * @return array
	 */
	function show_user_by_id( $uid )
	{
		$params=array();
		if ( $uid !== NULL ) {
			$this->id_format($uid);
			$params['uid'] = $uid;
		}
		return $this->oauth->get('users/show', $params );
	}

	/**
	 * OAuth��Ȩ֮�󣬻�ȡ��Ȩ�û���UID
	 * @return array
	 */
	function get_uid()
	{
		return $this->oauth->get( 'account/get_uid' );
	}
	
	protected function request_with_pager( $url, $page = false, $count = false, $params = array() )
	{
		if( $page ) $params['page'] = $page;
		if( $count ) $params['count'] = $count;
		return $this->oauth->get($url, $params );
	}

	protected function request_with_uid( $url, $uid_or_name, $page = false, $count = false, $cursor = false, $post = false, $params = array())
	{
		if( $page ) $params['page'] = $page;
		if( $count ) $params['count'] = $count;
		if( $cursor )$params['cursor'] =  $cursor;
		if( $post ) $method = 'post';
		else $method = 'get';
		if ( $uid_or_name !== NULL ) {
			$this->id_format($uid_or_name);
			$params['id'] = $uid_or_name;
		}
		return $this->oauth->$method($url, $params );
	}

	protected function id_format(&$id) {
		if ( is_float($id) ) {
			$id = number_format($id, 0, '', '');
		} elseif ( is_string($id) ) {
			$id = trim($id);
		}
	}
}
?>